package com.captjack.micro.search.web.controller;

import com.captjack.micro.api.article.MicroServiceTwo;
import com.captjack.micro.api.hello.MicroServiceOne;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * Description description.....
 *
 * @author Jack Sparrow
 * @version 1.0.0
 * @date 2018/7/31 11:11
 * package com.captjack.search.web.controller
 */
@RestController
@RequestMapping(value = "/hello", method = {RequestMethod.GET})
public class SearchController {

    private final MicroServiceTwo microServiceTwo;

    private final MicroServiceOne microServiceOne;

    @HystrixCommand(fallbackMethod = "error")
    @RequestMapping(value = "/hello")
    public String test() {
        try {
            System.out.println(microServiceOne.service(1, 2));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return UUID.randomUUID().toString();
    }

    private String error() {
        return "error!";
    }

    @Autowired
    public SearchController(MicroServiceTwo microServiceTwo, MicroServiceOne microServiceOne) {
        this.microServiceTwo = microServiceTwo;
        this.microServiceOne = microServiceOne;
    }

}
